﻿class Solution {
public:

    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0")
            return "0";
        string ret;
        int m = num1.size(), n = num2.size();
        vector<int> tmp(m + n - 1);
        int end1 = m - 1;
        while (end1 >= 0)
        {
            int end2 = n - 1;
            while (end2 >= 0)
            {
                tmp[end1 + end2] += (num1[end1] - '0') * (num2[end2] - '0');
                end2--;
            }
            end1--;
        }

        int k = m + n - 2, next = 0;
        while (k >= 0 || next)
        {
            int num = (k < 0) ? 0 : tmp[k];
            ret += (num + next) % 10 + '0';
            next = (num + next) / 10;
            k--;
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }



};